<template>
	<view class="maintainProjectCode">
		<view class="maintainProjectCode-content ff-bg-fff ff-color-222 ff-font-14 ff-margin-12 ff-border-radius-10">
			<view class="ff-font-weight-600 ff-padding-left-15 ff-padding-top-15 ff-font-15 ff-margin-bottom-5">维保合同编号
			</view>
			<view class="ff-flex-between ff-align-items-one ff-padding-15 ff-border-bottom">
				<view>合同编号</view>
				<input class="ff-text-right" v-model.trim="params.projectCode" placeholder="请输入合同编号"
					placeholder-style="color: #BCBFCC" type="text" />
			</view>
		</view>
		<view class="maintainProjectCode-but"><u-button type="primary" shape="circle"
				@click="submitCodeClick">确定提交</u-button></view>
		<f-loading ref="loading" />
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		name: 'maintainProjectCode',
		data() {
			return {
				params: {
					projectCode: '',
					projectId: ''
				}
			};
		},
		onLoad(e) {
			this.params.projectId = e.projectId;
			if (e.projectCode != 'null') {
				this.params.projectCode = e.projectCode
			} else {
				this.params.projectCode = ''
			}
		},
		methods: {
			// 提交合同编号------操作
			submitCodeClick() {
				if (!this.params.projectCode) {
					this.$refs.uToast.show({
						title: '请输入合同编号',
						type: 'error'
					});
					return;
				}
				this.$refs.loading.openLoading('提交中···'); // 打开loading动画
				this.$http
					.post({
						url: `/serviceOrg/project/addProjectCode`,
						data: this.params
					})
					.then(res => {
						// console.log('提交合同编号------操作返回的结果-----', res);
						this.$refs.loading.closeLoading(); // 关闭loading动画
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'success'
							});
							setTimeout(() => {
								// 刷新前一个页面 （配合前页面的onShow使用）
								uni.navigateBack({
									delta: 1,
									success: function() {
										let page = getCurrentPages().pop(); //跳转页面成功之后
										if (!page) return;
										page.onLoad(page.options); //如果页面存在，则重新刷新页面
									}
								});
							}, 500);
							// this.$pageJump.reLaunch('/pages/maintenance/mechanism/home/components/details/projectMaintenanceRecord?id=' + this.params.projectId);
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}

					});
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss">
	.maintainProjectCode {
		&-but {
			width: 90%;
			margin: 12% 5%;

			/deep/.u-size-default {
				height: 90rpx !important;
				line-height: 90rpx !important;
			}
		}
	}
</style>